package com.elong.android.specialhouse.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.elong.android.specialhouse.push.Message;

public class DatabaseHelper extends SQLiteOpenHelper {

	public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	public DatabaseHelper(Context context) {
		super(context, DB.DATABASE_NAME, null, DB.VERSION);
	}

	public void onCreate(SQLiteDatabase db) {
		// city district table.
		String cityExecStr = "CREATE TABLE IF NOT EXISTS " + DB.TABLE_CITY_DISTRICTS
				+ " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + DB.COL_CITY + " TEXT, " + DB.COL_LASTMODIFIED
				+ " DECIMAL, " + DB.COL_DATA + " TEXT);";
		db.execSQL(cityExecStr);

		String messageExecStr = "CREATE TABLE IF NOT EXISTS " + DB.TABLE_MESSAGE
				+ " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + Message.TITLE + " TEXT, " + Message.CONTENT + " TEXT, "
				+ Message.TIME + " TEXT, " + Message.TYPE + " INTEGER, " + Message.URL + " TEXT);";
		db.execSQL(messageExecStr);

	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion == 1) {
			String messageExecStr = "CREATE TABLE IF NOT EXISTS " + DB.TABLE_MESSAGE
					+ "(_id INTEGER PRIMARY KEY AUTOINCREMENT, " + Message.TITLE + " TEXT, " + Message.CONTENT
					+ " TEXT, " + Message.TIME + " TEXT, " + Message.TYPE + " INTEGER, " + Message.URL + " TEXT);";
			db.execSQL(messageExecStr);
		}
	}

}
